package com.example.transferfile;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint("SimpleDateFormat")
public class myadapter extends BaseAdapter{

	Context context;
	List<String> name;
	String currentPath;
	
	public myadapter(Context context, List<String> ten, String path) {
		
		this.context=context;
		this.name = ten;
		currentPath = path;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inf=(LayoutInflater)
				context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowview=inf.inflate(R.layout.row,parent, false);
		
		TextView textview=(TextView)rowview.findViewById(R.id.rowtext);
		ImageView imageview=(ImageView)rowview.findViewById(R.id.imageView1);
		TextView textday = (TextView)rowview.findViewById(R.id.rowday);
		
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");
		Date date = new Date();
		String ngay = dateFormat.format(date);
		
		textday.setText(ngay);
		textview.setText(name.get(position));
		File f = new File(currentPath+"/"+name.get(position));
		if(f.isDirectory()){
			imageview.setImageResource(R.drawable.ic_folder);
		}else{

			imageview.setImageResource(R.drawable.ic_file);
		}
		return rowview;
	}
	@Override
	public int getCount() {
		if(name == null)
		{
			return 0;
		}
		return name.size();
	}
	@Override
	public Object getItem(int position) {
		return null;
	}
	@Override
	public long getItemId(int position) {
		return 0;
	}
}
